package example.service;

import example.model.MyUserDetail;
import example.model.SysUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * TODO
 *
 * @author zgq
 * @date 2020/10/22 15:08
 */
@Service
public class MyUserDetailService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        if (!StringUtils.equalsIgnoreCase(s, "zhang")) {
            throw new RuntimeException("登陆失败：用户名不一样");
        }
        SysUser sysUser = new SysUser(s, "3433502", "张国庆");
        return new MyUserDetail(sysUser);
    }
}
